<script setup lang="ts">
import { computed } from "vue";

defineOptions({
  name: "deviceStatisticsTasksTotal"
});

interface Props {
  data?: any;
  dark?: boolean;
}

const props = withDefaults(defineProps<Props>(), { dark: false });

const percentage = computed(() => {
  if (props?.data?.done && props?.data?.total) {
    const { done, total } = props.data;
    const p = Number(done) / Number(total);
    return Math.floor(p * 100);
  } else {
    return 0;
  }
});
</script>

<template>
  <div class="tasks-total-content">
    <div class="tasks-total-content-left">
      <div class="tasks-total-content-title" :class="{ dark }">{{ data?.label }}</div>
      <div class="tasks-total-content-progress">
        <px-progress
          :text-inside="true"
          :stroke-width="18"
          duration="10"
          striped
          striped-flow
          :color="dark ? '#04FF9D' : '#19D08D'"
          :percentage="percentage"
        />
      </div>
      <div class="tasks-total-content-data">
        <span class="data-text color-done" :class="{ dark }">{{ data?.done || "--" }} </span>
        <span class="data-text color-total">&nbsp;/&nbsp;{{ data?.total || "--" }}</span>
      </div>
    </div>

    <div class="tasks-total-content-legend">
      <div class="legend-item">
        <span class="legend-icon background-done" />
        <span class="legend-text" :class="{ dark }">已完成</span>
      </div>
      <div class="legend-item">
        <span class="legend-icon background-total" />
        <span class="legend-text" :class="{ dark }">合计任务数</span>
      </div>
    </div>
  </div>
</template>

<style lang="scss" scoped>
// $colorDone: #28d892ff;
$colorDone: #19d08d;
$darkColorDone: #04ff9d;
$colorTotal: var(--px-color-primary);

.tasks-total-content {
  display: flex;
  flex-wrap: nowrap;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  width: 100%;

  .dark {
    color: #fff !important;

    &.color-done {
      color: $darkColorDone !important;
    }

    &.background-done {
      background-color: $darkColorDone !important;
    }
  }

  .color-done {
    color: $colorDone;
  }

  .color-total {
    color: $colorTotal;
  }

  .data-text {
    font-size: 20px;
    font-weight: 600;
    line-height: 1;
    white-space: nowrap;
  }

  .background-done {
    background-color: $colorDone;
  }

  .background-total {
    background-color: $colorTotal;
  }

  .tasks-total-content-left {
    display: flex;
    flex-wrap: nowrap;
    gap: 16px;
    align-items: center;

    .tasks-total-content-title {
      font-size: 16px;
      font-weight: 600;
      line-height: 1;
      color: #333;
      white-space: nowrap;
    }

    .tasks-total-content-progress {
      width: 200px;
    }

    .tasks-total-content-data {
      display: flex;
      align-items: center;
    }
  }

  .tasks-total-content-legend {
    display: flex;
    gap: 12px;
    align-items: center;

    .legend-item {
      display: flex;
      gap: 8px;
      align-items: center;

      .legend-icon {
        width: 8px;
        height: 8px;
        border-radius: 50%;
      }

      .legend-text {
        font-size: 12px;
        line-height: 1;
        color: #333;
        white-space: nowrap;
      }
    }
  }
}
</style>
